"""
用户相关Schema
"""
from typing import Optional
from datetime import datetime
from pydantic import BaseModel, EmailStr


class UserLogin(BaseModel):
    """用户登录"""
    username: str
    password: str


class TokenResponse(BaseModel):
    """Token响应"""
    access_token: str
    refresh_token: str
    token_type: str = "bearer"


class UserBase(BaseModel):
    """用户基础信息"""
    username: str
    email: EmailStr
    nickname: Optional[str] = None
    avatar: Optional[str] = None


class UserCreate(UserBase):
    """创建用户"""
    password: str
    role_id: Optional[int] = None


class UserUpdate(BaseModel):
    """更新用户"""
    email: Optional[EmailStr] = None
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    role_id: Optional[int] = None
    status: Optional[int] = None


class UserResponse(UserBase):
    """用户响应"""
    id: int
    role_id: Optional[int]
    status: int
    last_login_time: Optional[datetime]
    created_at: datetime
    
    class Config:
        from_attributes = True


class PasswordChange(BaseModel):
    """修改密码"""
    old_password: str
    new_password: str

